#include "MRegisterCPlus.h"
#include <QDebug>
#include <QQuickStyle>
#include "../../publicinc.h"
#include "MPropertyMap.h"


static QJSValue JsonProvider(QQmlEngine* engine , QJSEngine *scriptEngine) {
    Q_UNUSED(engine);
    Q_UNUSED(scriptEngine);
    QJSValue value = scriptEngine->newQObject(QReadJson::GetInstance());
    return value;
}


static QJSValue DirProvider(QQmlEngine* engine , QJSEngine *scriptEngine) {
    Q_UNUSED(engine);
    Q_UNUSED(scriptEngine);
    QJSValue value = scriptEngine->newQObject(DirOp::GetInstance());
    return value;
}

void MRegisterCPlus::registerJSEngineType()
{
    qmlRegisterSingletonType("Quick.Package", 1, 0, "JsonEngine", JsonProvider);
    qmlRegisterSingletonType("Quick.Package", 1, 0, "Dir", DirProvider);

}

MRegisterCPlus::MRegisterCPlus(QQmlContext *engine)
{
    m_context = engine;
    _InitObject();
}

void MRegisterCPlus::_InitObject()
{

}

void MRegisterCPlus::_initSystem()
{
    m_context->setContextProperty("$SH", ScreenHelper::GetInstance());
    m_context->setContextProperty("$Mp", MPropertyMap::GetInstance());
    m_context->setContextProperty("availableStyles", QQuickStyle::availableStyles());
}

void MRegisterCPlus::_initQMLComponent()
{
    //m_context->setContextProperty("$HalconProvider", ImageProvider::GetInstance());
}

void MRegisterCPlus::_initGlobalData()
{

}

void MRegisterCPlus::_initConfFile()
{
    m_context->setContextProperty("AppPath", AppPath::GetInstance());

}

void MRegisterCPlus::_initInterface()
{
    //m_context->setContextProperty("$SplashInterface", SplashInterface::GetInstance());
    StandardItemModel *aaaa = new StandardItemModel();
    m_context->setContextProperty("StandardItemModel",  aaaa);
}

void MRegisterCPlus::registerQMLType()
{
    //qmlRegisterType<HalconForm>("Quick.Halcon", 1, 0,"ImageLoader");
    qmlRegisterType<TableModel>("TableModel", 0, 1, "TableModel");
    qmlRegisterType<ResultModel>("TableModel", 0, 1, "ResultModel");
    //qmlRegisterType<StandardItemModel>("StandardItemModel", 0, 1, "StandardItemModel");
    //qRegisterMetaType<QStandardItemModel>("QStandardItemModel");
    qRegisterMetaType<QHash<int,QVariantList>>("qmlModel");




}



void MRegisterCPlus::_StartRegster()
{
    registerQMLType();
    registerJSEngineType();
    _initSystem();
    _initInterface();
    _initConfFile();
    _initGlobalData();
    _initQMLComponent();
    _ConnectQMLSignals();
}

void MRegisterCPlus::_ConnectQMLSignals()
{

}



